package cn.zlj.pethome.order.controller;

import cn.zlj.pethome.basic.QueryResult;
import cn.zlj.pethome.basic.util.AjaxResult;
import cn.zlj.pethome.order.service.IOrderAuditLogService;
import cn.zlj.pethome.order.domain.OrderAuditLog;
import cn.zlj.pethome.order.query.OrderAuditLogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderAuditLog")
public class OrderAuditLogController {
    @Autowired
    public IOrderAuditLogService orderAuditLogService;


    /**
     * 保存和修改公用的
     * @param orderAuditLog  传递的实体
     * @return AjaxResult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody OrderAuditLog orderAuditLog){
        try {
            if( orderAuditLog.getId()!=null)
                orderAuditLogService.update(orderAuditLog);
            else
                orderAuditLogService.add(orderAuditLog);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            orderAuditLogService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public OrderAuditLog get(@PathVariable("id")Long id)
    {
        return orderAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<OrderAuditLog> list(){

        return orderAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public QueryResult<OrderAuditLog> json(@RequestBody OrderAuditLogQuery query)
    {
        return orderAuditLogService.queryByPage(query);
    }
}
